import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/refresh-helper/refresh_header.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class PluginRefreshClassicHeader extends StatefulWidget {
  @override
  _PluginRefreshClassicHeaderState createState() =>
      _PluginRefreshClassicHeaderState();
}

class _PluginRefreshClassicHeaderState
    extends State<PluginRefreshClassicHeader> {
  RefreshController _controller = RefreshController();

  // 下拉刷新
  Future _onRefresh() async {
    await Future.delayed(Duration(milliseconds: 1500));
    _controller.refreshCompleted();
  }

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
      controller: _controller,
      enablePullDown: true,
      onRefresh: _onRefresh,
      header: AppRefreshHeader(
        paddingTop: 10,
        backgroundImage: ExtendedImage.network(
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fyouimg1.c-ctrip.com%2Ftarget%2Ftg%2F019%2F373%2F540%2Fc03ed83ed44b45a7888d65817e162e16.jpg&refer=http%3A%2F%2Fyouimg1.c-ctrip.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1622187804&t=f819f2ca13224408e0def61188a70c72')
            .image,
      ),
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            title: Text('item_$index'),
          );
        },
        itemCount: 30,
      ),
    );
  }
}
